const wall = 1;
const roud = 0;
const start = 2;
const end = 3;
const line = 4;


function disPlayMap(map) {
    console.log("\n");
    for (let i = 0; i < map.length; i++) {
        let str = "                    ";
        for (let j = 0; j < map[0].length; j++) {
            if (map[i][j] == roud) {
                str += " * "; //可行区域
            } else if (map[i][j] == wall) {
                str += " | "; //墙
            } else if (map[i][j] == start) {
                str += " S "; //起点
            } else if (map[i][j] == end) {
                str += " E "; //终点
            } else if (map[i][j] == line) {
                str += " X "; //路径
            }
        }
        console.log(str, "\n");
    }
}

function generateMap(path) {
    for (let i = 0; i < path.length; i++) {
        if(i == 0 || i == path.length -1){
            let temp = path[i];
            mv[temp.row][temp.col] = i==0?end:start;
        }else{
            let temp = path[i];
            mv[temp.row][temp.col] = line;
        }
    }
}


//测试
let mv = require("./map");
const astar = require("./astar");

astar.initMap(mv);

let t1 = new Date().getTime();
let t2 = t1;
t1 = process.uptime()*1000;

let path = astar.search(6, 4, 6, 6);

t2 = process.uptime()*1000;
console.log("                   search finished,cost time:", t2-t1,"ms");

generateMap(path);
disPlayMap(mv);